
import java.util.*; 

public class WebObject implements Comparator, Comparable{
	private static Random rand = new Random(System.currentTimeMillis());
	private int size;
	
	/* This is the constructor. It should create a new web object with a random size in the 
	 * range of 1KB to 1MB (1024 KB). 
	 * */
   public WebObject() {
	  // complete code here
	  this.size = WebObject.rand.nextInt(1024) + 1;
   } 

   public WebObject(int size){
	   this.size = size;
   }
	/* This method returns the size of the WebObject 
	 * */
   public int getSize() { return size;}

	/* This method should create and return an exact copy of the WebObject.
	 * */
	public WebObject copy() { 
		return new WebObject(this.size);
	}

   /* This method defines how to compare two objects of the WebObject class. It returns 0 if the 
    * sizes of two WebObjects are equal, a negative number if the size of Obj1 is smaller 
    * than the size of the Obj2, or a positive number if the size of Obj1 is 
    * is larger Obj2. This method is required because we are 
    * implementing the Comparator interface. 
    * */
	public int compare(Object Obj1, Object Obj2) {
		int result = ((WebObject) Obj1).getSize() - ((WebObject) Obj2).getSize();
		return result;
	}
	
	public int compareTo(Object Obj1){
		int result = this.getSize() - ((WebObject) Obj1).getSize();
		return result;
	}

}